package com.test.slice;

import com.ms.banner.Banner;
import com.ms.banner.BannerConfig;
import com.ms.banner.Transformer;
import com.ms.banner.view.BannerViewPager;
import com.test.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.ListContainer;

import java.util.ArrayList;
import java.util.List;

import static com.test.MyApplication.*;

public class BannerAnimationAbilitySlice extends AbilitySlice {
    private Banner banner;
    private List<Class<? extends BannerViewPager.PageTransformer>> transformers = new ArrayList<>();
    public void initData() {
        transformers.add(Transformer.Default);
        transformers.add(Transformer.Accordion);
        transformers.add(Transformer.BackgroundToForeground);
        transformers.add(Transformer.ForegroundToBackground);
        transformers.add(Transformer.CubeIn);//兼容问题，慎用
        transformers.add(Transformer.CubeOut);
        transformers.add(Transformer.DepthPage);
        transformers.add(Transformer.FlipHorizontal);
        transformers.add(Transformer.FlipVertical);
        transformers.add(Transformer.RotateDown);
        transformers.add(Transformer.RotateUp);
        transformers.add(Transformer.ScaleInOut);
        transformers.add(Transformer.FlipHorizontal);//Scale
        transformers.add(Transformer.FlipHorizontal);//ScaleRight
        transformers.add(Transformer.Stack);
        transformers.add(Transformer.Tablet);
        transformers.add(Transformer.ZoomIn);
        transformers.add(Transformer.ZoomOut);
        transformers.add(Transformer.ZoomOutSlide);
        transformers.add(Transformer.Drawer);
    }

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_banner_animator);
        ListContainer listContainer = (ListContainer) findComponentById(ResourceTable.Id_list);
        banner = (Banner) findComponentById(ResourceTable.Id_banner);
        //简单使用
        banner.setBannerTitles(getDataStr())
                .setPages(getDataInt(), null)
                .setAutoPlay(false)
                .setLoop(false)
                .setDelayTime(3000)
                .setIndicatorGravity(BannerConfig.CENTER)
                .start();

        initData();
        List<SampleItem> list = getSampleItems(getAnimatorStr());
        SampleItemProvider sampleItemProvider = new SampleItemProvider(list, this);
        listContainer.setItemProvider(sampleItemProvider);
        listContainer.setItemClickedListener((container, component, position, id) -> {
                banner.setBannerAnimation(transformers.get(position));
                }
        );
    }

}